home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 7
/
FM Towns Free Software Collection 7.iso
/
t_os
/
gpen32k
/
source.exe
/
LIB
/
OSRC
/
OTIFFLOA.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-01
|
2KB
|
95 lines
/************************************************************
* 共通一般ライブラリー OKOME System 2 *
************************************************************/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <EGB.H>
#include <tifflib.h>
#include <normlib.h>
int tiffload(char *name, int xf, int yf)
{
char p[2048];
int i, ofs, tags, x, y, pix, y2=0, gm;
/* int ask=0, pal=0, palof=0, size=0; */
FILE *fp;
if ((fp = fopen(name, "rb")) == NULL) {
fclose(fp);
return (-1);
}
fread(p, 1, 8, fp); /* 識別 */
if (strncmp( p, "II*", 3) != 0) {
fclose(fp);
return (-2);
}
ofs = DWORD(p + 4);
fseek( fp, ofs, SEEK_SET );
fread( &p[8], 1, 2, fp );
for ( tags = WORD(p + 8); tags>0; tags--) {
fread( p, 1, 12, fp );
i = DWORD(p + 8);
switch(WORD(p)) {
case 0:
tags = 0;
break;
case 0x100:
x = i;
break;
case 0x101:
y = i;
break;
case 0x102:
pix = i;
break;
/* case 0x103:
ask = i;
break; */
/* case 0x106:
pal = i;
break; */
case 0x111:
ofs = i;
break;
case 0x116:
y2 = i;
break;
/* case 0x117:
size = i;
break; */
/* case 0x140:
palof = i;
break; */
}
}
i = EGB_getWritePage(0,0);
i = (EGB_getResolution( NULL, NULL ) >> (i*8)) & 0xff;
EGB_getModeInfo( i, NULL,NULL, NULL,NULL, &gm);
if ((1<<pix) == gm || (pix == 16 && gm == 32768))
{
fseek( fp, ofs, SEEK_SET );
for ( y2 = 0; y2 <= y; y2++ ) {
fread( p, 1, ceil( x*pix/8.0 ), fp );
egbput(xf, yf+y2, xf+x, yf+y2, p);
}
i = 0;
} else {
if (pix == 1)
{
fseek( fp, ofs, SEEK_SET );
for ( y2 = 0; y2 <= y; y2++ ) {
fread( p, 1, ceil( x/8.0 ), fp );
egbputc(xf, yf+y2, xf+x, yf+y2, p);
}
i = 0;
} else {
i = pix;
}
}
fclose(fp);
return (i);
}